#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Dict, List
from collections import defaultdict

class FilterStats:
    """筛选统计器，用于统计各个筛选器的筛选情况"""
    
    def __init__(self):
        """初始化统计器"""
        self.stats = defaultdict(int)
        self.detailed_stats = defaultdict(list)
    
    def record_filter(self, filter_name: str, filter_reason: str, unit_info: Dict = None):
        """记录一次筛选事件"""
        self.stats[filter_name] += 1
        
        # 记录详细信息（可选）
        if unit_info:
            self.detailed_stats[filter_name].append({
                'reason': filter_reason,
                'unit_info': unit_info
            })
    
    def get_stats(self) -> Dict[str, int]:
        """获取筛选统计"""
        return dict(self.stats)
    
    def get_detailed_stats(self) -> Dict[str, List]:
        """获取详细统计信息"""
        return dict(self.detailed_stats)
    
    def print_summary(self):
        """打印统计摘要"""
        print("=== 筛选器统计摘要 ===")
        total_filtered = sum(self.stats.values())
        print(f"总筛选数量: {total_filtered}")
        print("\n各筛选器统计:")
        for filter_name, count in sorted(self.stats.items(), key=lambda x: x[1], reverse=True):
            print(f"  {filter_name}: {count} 条")
    
    def reset(self):
        """重置统计"""
        self.stats.clear()
        self.detailed_stats.clear() 